<import template="/panel/_header" />
<div class="page-container">
    <div class="main-content">
        <div class="page-title">
            <div class="title-env">
                <h1 class="title">节点列表</h1>
                <p class="description">请勿在任何地方公开节点地址！</p>
            </div>
            <div class="breadcrumb-env">
                <ol class="breadcrumb bc-1"><li><a href="/member"><i class="fa-home"></i>主页</a></li><li><a href="javascript:;">节点列表</a></li><li class="active"><strong>节点信息</strong></li></ol>
            </div>
        </div>
        <div class="row">
            <!-- /.box-begin -->
            <loop variable="$nodes" key="$key" value="$node">
                <div class="col-sm-6">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <i class="fa fa-angle-right"></i> {$node->name}
                            <div class="dropdown">
                                <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                    操作 <span class="caret"></span>
                                </a>
                                <ul class="dropdown-menu">
                                    <li role="presentation"><a role="menuitem" tabindex="-1" href="javascript:getNodeInfo('{$node->id}')">节点信息</a></li>
                                    <li role="presentation"><a role="menuitem" tabindex="-1" href="javascript:addToAndroid('{$node->id}')">添加至安卓客户端</a></li>
                                </ul>
                            </div>
                        </div>
                        <div class="panel-body">
                            <span class="btn btn-secondary" style="user-select: all">{$node->server}</span>
                            <button class="btn btn-orange">{$node->status}</button>
                            <if condition="$node->custom_method && $user->method">
                                <button class="btn btn-turquoise">{$user->method}</button>
                                <else>
                                    <button class="btn btn-turquoise">{$node->method}</button>
                            </if>
                            <br>
                            <p>{$node->info}</p>
                        </div>
                    </div>
                </div>
            </loop>
            <!-- /.pro-box-begin -->
            <loop variable="$nodeVip" key="$key" value="$node">
                <if condition="$user->enable == 1 && ($user->plan == 'VIP' || $user->plan == 'SVIP')">
                    <div class="col-sm-6">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <i class="fa fa-code"></i> Pro节点 - {$node->name}
                                <div class="dropdown">

                                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                        操作 <span class="caret"></span>
                                    </a>
                                    <ul class="dropdown-menu">
                                        <li role="presentation"><a role="menuitem" tabindex="-1" href="javascript:getNodeInfo('{$node->id}')">节点信息</a></li>
                                        <li role="presentation"><a role="menuitem" tabindex="-1" href="javascript:addToAndroid('{$node->id}')">添加至安卓客户端</a></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="panel-body">
                                <span class="btn btn-secondary" style="user-select: all">{$node->server}</span>
                                <button class="btn btn-orange">{$node->status}</button>
                                <if condition="$node->custom_method && $user->method">
                                    <button class="btn btn-turquoise">{$user->method}</button>
                                    <else>
                                        <button class="btn btn-turquoise">{$node->method}</button>
                                </if>
                                <br>
                                <p>{$node->info}</p>
                            </div>
                        </div>
                    </div>
                    <else>
                        <div class="col-sm-6">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <i class="fa fa-code"></i> Pro节点 - {$node->name}
                                    <div class="dropdown"></div>
                                </div>
                                <div class="panel-body">
                                    <button class="btn btn-orange">无权使用</button>
                                    <br>
                                    <p>*您无权使用该节点</p>
                                </div>
                            </div>
                        </div>
                </if>
            </loop>
        </div>
        <!-- Node Info Modal-->
        <div class="modal fade" id="node-info-modal-temp">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title"></h4>
                    </div>
                    <div class="modal-body">
                        <div id="modal-isload">Content is loading...</div>
                        <div id="modal-isbody" style="display: none;">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="box box-solid">
                                        <div class="box-header">
                                            <h4 class="box-title">配置JSON</h4>
                                        </div>
                                        <!-- /.box-header -->
                                        <div class="box-body">
                                            <textarea class="form-control" rows="8" id="node-info-json" readonly="readonly"></textarea>
                                        </div>
                                        <!-- /.box-body -->
                                    </div>
                                    <!-- /.box -->
                                    <div class="box box-solid">
                                        <div class="box-header">
                                            <h4 class="box-title">配置地址</h4>
                                        </div>
                                        <!-- /.box-header -->
                                        <div class="box-body">
                                            <input class="form-control" id="node-info-url" readonly="readonly">
                                        </div>
                                        <!-- /.box-body -->
                                    </div>
                                    <!-- /.box -->
                                    <div class="box box-solid">
                                        <div class="box-header">
                                            <h4 class="box-title">二维码</h4>
                                        </div>
                                        <!-- /.box-header -->
                                        <div class="box-body">
                                            <div class="text-center">
                                                <div id="node-info-qrcode"></div>
                                            </div>
                                        </div>
                                        <!-- /.box-body -->
                                    </div>
                                    <!-- /.box -->
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    </div>

                </div>

            </div>
        </div>
        <script src="{RESOURCE}/js/jquery.qrcode.min.js"></script>
        <script type="text/javascript">
            node_modal_init();
            function node_modal_init() {
                $(function(){
                    if($("#node-info-modal-temp").length > 0 && $("#node-info-modal").length <= 0) {
                        $("body").append('<div class="modal fade" id="node-info-modal"></div>');
                        $("#node-info-modal").append($("#node-info-modal-temp").html());
                        $("#node-info-modal-temp").remove();
                    }
                });
            }
            var modal_default_body = jQuery('#node-info-modal .modal-body').html();

            function getNodeInfo(nodeId) {
                $("#node-info-modal .modal-body").html(modal_default_body);
                reset(false);
                $.ajax({
                    url: "/node/getNodeInfo.json",
                    method: "POST",
                    dataType: "json",
                    data: {id: nodeId},
                    success: function (result) {
                        if(result.code != 200){
                            $('#node-info-modal').modal('hide');
                            showToastr(result.message, 0, 3000, '系统错误');
                            return;
                        }
                        if(result.data.error == 0 && result.data.node != null && result.data.info != null) {
                            $('#node-info-modal .modal-title').text(result.data.node.name);
                            $('#node-info-modal #node-info-json').text(result.data.info.ssjson);
                            $('#node-info-modal #node-info-url').val(result.data.info.ssurl);
                            $('#node-info-modal #node-info-qrcode').empty().qrcode({width:200,height:200,text: result.data.info.ssurl});
                            reset(true);
                        } else {
                            showToastr(result.data.message, 0);
                        }

                    },
                    error: function (Xhr) {
                        showToastr("出现未知错误，请重试或联系管理员", 0);
                    }
                });
                $('#node-info-modal').modal('show', {backdrop: 'static'});
            }
            function addToAndroid(nodeId) {
                $.ajax({
                    url: "/node/getNodeInfo.json",
                    method: "POST",
                    dataType: "json",
                    data: {id: nodeId},
                    success: function (result) {
                        if(result.code != 200){
                            showToastr(result.message, 0, 3000, '系统错误');
                            return;
                        }
                        if(result.data.error == 0 && result.data.node != null && result.data.info != null) {
                            location.href = result.data.info.ssurl;
                        } else {
                            showToastr(result.data.message, 0);
                        }
                    },
                    error: function (Xhr) {
                        showToastr("出现未知错误，请重试或联系管理员", 0);
                    }
                });
            }
            function reset(isShow) {
                try {
                    if(typeof (eval(pageJSload)) == 'function') {
                        pageJSload();
                    }
                } catch (e) {}

                if(isShow) {
                    jQuery('#modal-isload').hide();
                    jQuery('#modal-isbody').show();
                } else {
                    jQuery('#modal-isload').show();
                    jQuery('#modal-isbody').hide();
                }
            }
        </script>
    </div>
</div>
<import template="/panel/_footer" />